package com.tulin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.codec.CodecConfigurer;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

@Configuration
public class WebConfig {


    @Bean
    public UserDetailsService userDetailsService(PasswordEncoder passwordEncoder) {
        InMemoryUserDetailsManager userDetailsManager = new InMemoryUserDetailsManager();
        UserDetails user1 = User.builder()
                .username("student")
                .password(passwordEncoder.encode("student"))
                .roles("student")
                .build();
        UserDetails user2 = User.builder()
                .username("teacher")
                .password(passwordEncoder.encode("teacher"))
                .roles("teacher")
                .build();
        UserDetails user3 = User.builder()
                .username("admin")
                .password(passwordEncoder.encode("admin"))
                .roles("admin")
                .build();
        userDetailsManager.createUser(user1);
        userDetailsManager.createUser(user2);
        userDetailsManager.createUser(user3);
        return userDetailsManager;
    }

    @Bean
    public PasswordEncoder getPassWordEncoder(){
        return new BCryptPasswordEncoder(10);
// return NoOpPasswordEncoder.getInstance();
    }

}
